package hy.service.impl;

import com.alibaba.fastjson.JSON;
import hy.beans.User;
import hy.dao.UserDao;
import hy.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;

@Service
public class UserServiceImpl implements UserService {
    @Autowired
    UserDao dao;
    @Autowired
    StringRedisTemplate tmp;

    public boolean doLogin(User user) {
        User u=dao.selectPasswordByPhone(user.getPhone());
        if(u.getPassword().equals(user.getPassword())){
            tmp.opsForHash().put("phones",user.getPhone(), JSON.toJSONString(u));
            return true;
        }
        return false;
    }

    public User get(String phone) {
        if(phone==null){
            return new User();
        }
        String userMsg=(String)tmp.opsForHash().get("phones", phone);
        return JSON.parseObject(userMsg,User.class);
    }
}